﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Jarvis.Server.IoC;
using Jarvis.Server.Repositories;
using Jarvis.WCF.DataContracts;
using Ninject;
using Ninject.Extensions.Logging.NLog2;
using Ninject.Modules;
using Action = System.Action;


namespace Jarvis.Server
{
    static class Program
    {
        /// <summary>
        /// Punto di ingresso principale dell'applicazione.
        /// </summary>
        static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "Main Thread";
            Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var modules = new INinjectModule[]
                              {
                                  new NhibernateModule(),
                                  new JarvisModule(), 
                                  new WcfModule(),
                                  new AutoMapperModule(), 
                              };

            var kernel = new StandardKernel(modules);
            kernel.Bind<JarvisServiceHost>().ToSelf();
            ServiceBase[] ServicesToRun;
            
            

#if DEBUGSERVICE
            kernel.Get<JarvisServiceHost>().DebugOnStart(args);
            
#else
            ServicesToRun = new ServiceBase[] 
            { 
                kernel.Get<JarvisServiceHost>()
            };
            ServiceBase.Run(ServicesToRun);
#endif
        }
    }
}
